#!/bin/sh
case "$1" in
  start)
    # Start ubiscrubber for every ubi volume we can find.
    # Use ubinfo to get a list of such volumes.
    lsubi |
    while read node name; do
      if [ "$name" = rootfs ] || [ "$name" = config ] || [ "$name" = user ];
      then
	echo "Starting ubiscrubber for $node ($name)."
	supernice babysit 60 sh -ec \
	    "while :; do ubiscrubber /dev/$node; done" 2>&1 |
	      logos "ubiscrubber ${node##*/}" &
      fi
    done
    ;;
  stop)
    pkillwait -x ubiscrubber
    ;;
  restart|reload)
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
